package com.example.xiaodu.yuejian12.Activity;

import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xiaodu.yuejian12.Bean.ActivityBean;
import com.example.xiaodu.yuejian12.Listener.RetrofitListener;
import com.example.xiaodu.yuejian12.Model.UserModel;
import com.example.xiaodu.yuejian12.R;
import com.squareup.picasso.Picasso;

import static com.example.xiaodu.yuejian12.R.id.signUp;

/**
 * Created by xiaodu on 2018/10/10.
 */

public class ActivityDetailActivity extends AppCompatActivity {
    private TextView activityName,activityTime,activityPlace,activityIntro;
    private Button signUP;
    private ImageView imageView;
    private UserModel userModel;
    private int activityID;
    private RetrofitListener<ActivityBean> listener;

    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_detail2);

        initView();
        initListener();
        getData();
        initClick();
    }

    public void initView(){
        imageView=(ImageView)findViewById(R.id.activity_picture);
        activityName=(TextView)findViewById(R.id.name);
        activityTime=(TextView)findViewById(R.id.time);
        activityPlace=(TextView)findViewById(R.id.place);
        activityIntro=(TextView)findViewById(R.id.intro);
        signUP=(Button)findViewById(signUp);


    }

    public void initListener(){
        listener=new RetrofitListener<ActivityBean>() {
            @Override
            public void onSuccess(ActivityBean activityBean) {
                activityName.setText(activityBean.getAcname());
                activityTime.setText(activityBean.getAtime());
                activityPlace.setText(activityBean.getPlace());
                activityIntro.setText(activityBean.getAcintro());
                Picasso.with(imageView.getContext()).load("http://10.0.2.2/yuejian/public/static/activity/"+activityBean.getApic()).into(imageView);

            }

            @Override
            public void onFail(String msg) {

            }
        };
    }

    public void getData(){
        userModel=new UserModel();
        userModel.getActivityDetail(getIntent().getIntExtra("activityID",1),listener);
    }

    public void initClick(){
        signUP.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                Intent intent=new Intent(ActivityDetailActivity.this,SignupActivity.class);
                intent.putExtra("activityID",activityID);
                startActivity(intent);
            }
        });
    }
}
